package pub.tbc.hh.mall.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pub.tbc.hh.mall.mapper.ShoppingCartMapper;
import pub.tbc.hh.mall.service.ShoppingCartService;
import pub.tbc.toolkit.core.collect.Maps;

import java.util.List;
import java.util.Map;

/**
 * @author tbc  by 2018/5/26
 */
@Service
public class ShoppingCartServiceImpl implements ShoppingCartService {

    @Autowired
    private ShoppingCartMapper mapper;


    private Map<String, Object> transition(Map<Long, List<Map<Long, Integer>>> params ){
        Long userId = params.keySet().stream().findAny().get();
        List<Map<Long, Integer>> vv = params.values().stream().findAny().get();

        Map<String, Object> map = Maps.newHashMap();
        map.put("userId", userId);
        map.put("list", vv);
        return map;
    }

    @Override
    public Map<String, Object> queryWaresByUserId(int waresId) {
        return null;
    }

    @Override
    public boolean addWares(Map<Long, List<Map<Long, Integer>>> params) {

        mapper.addBatch(transition(params));

        return true;
    }

    @Override
    public boolean delWares(Map<String, Object> params) {
        return false;
    }

    @Override
    public boolean batchAddWares(Map<Long, List<Map<Long, Integer>>> params) {
        mapper.addBatch(transition(params));
        return true;
    }

    @Override
    public boolean batchDelWares(Map<String, Object> params) {
        return false;
    }
}
